//package person.twj;
//
//import lombok.AllArgsConstructor;
//import lombok.Builder;
//import lombok.Getter;
//import lombok.Setter;
//import org.springframework.security.authentication.AnonymousAuthenticationToken;
//import org.springframework.security.authentication.ProviderManager;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContext;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.password.NoOpPasswordEncoder;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.Map;
//
//public class TestMain {
//    public static void main(String[] args) {
//        String username = "admin";
//        String password = "123456";
//        // SecurityContextHolder
//
//
//        SecurityContext context = SecurityContextHolder.createEmptyContext();
//        Authentication anAuthentication = new UsernamePasswordAuthenticationToken(
//                SysUser.builder().username(username).password(password).build(),
//                password);
//        context.setAuthentication(anAuthentication);
//        SecurityContextHolder.setContext(context);
//
//        // ProviderManager implements AuthenticationManager
//        //
//        DaoAuthenticationProvider provider = new DaoAuthenticationProvider(new NoOpPasswordEncoder());
//        provider.setUserDetailsService(new UserDetailsService() {
//            @Override
//            public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//                return User.builder().username("admin").password("123456").build();
//            }
//        });
//        ProviderManager providerManager = new ProviderManager(provider);
//        Authentication authentication = providerManager.authenticate(
//                SecurityContextHolder.getContext().getAuthentication()
//        );
//        if(authentication==null){
//            System.out.println("验证失败");
//            return;
//        }
//
//        System.out.println("身份验证成功");
//    }
//    @Getter
//    @Setter
//    @Builder
//    class SysUser{
//        private String username;
//        private String password;
//
//    }
//}
//
